﻿using System;
using System.Collections.ObjectModel;
using System.Linq;
using SSM.BusinessLayer.Enums;

namespace SSM.BusinessLayer
{
	public class LogItemCollection : Collection<LogItem>
	{
		#region Main methods

		public void AddRange(LogItemCollection items)
		{
			foreach (LogItem item in items)
			{
				Add(item);
			}
		}

		public LogItemCollection GetAlerts()
		{
			LogItemCollection alerts = new LogItemCollection();

			foreach (LogItem item in this)
			{
				alerts.Add(item);
			}

			for (Int32 a = 0; a < alerts.Count; a++)
			{
				if (alerts[a].Severity == AlertSeverity.Critical)
				{
					alerts.Add(alerts[a]);

					for (Int32 b = a + 1; b < alerts.Count(); b++)
					{
						if (alerts[a].MonitoredItem.Title == alerts[b].MonitoredItem.Title)
						{
							alerts.RemoveAt(b);
							b -= 1;
						}
					}
				}
				if (alerts[a].Severity == AlertSeverity.Warning)
				{
					alerts.Add(alerts[a]);
				}
			}

			return alerts;
		}

		#endregion
	}
}